<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改电子名片信息表')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-card-edit" th:object="${businessCard}">
            <input name="bcId" th:field="*{bcId}" type="hidden">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">头像：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="bcUserImg" th:field="*{bcUserImg}">
                       <div class="file-loading">
                            <input class="form-control file-upload" id="bcUserImg" name="file" type="file">
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">手机号：</label>
                    <div class="col-sm-8">
                        <input name="bcUserPhone" th:field="*{bcUserPhone}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">公司地址：</label>
                    <div class="col-sm-8">
                        <input name="bcAddress" th:field="*{bcAddress}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">x坐标：</label>
                    <div class="col-sm-8">
                        <input name="bcXCoordinate" th:field="*{bcXCoordinate}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">y坐标：</label>
                    <div class="col-sm-8">
                        <input name="bcYCoordinate" th:field="*{bcYCoordinate}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">公司名称：</label>
                    <div class="col-sm-8">
                        <input name="bcName" th:field="*{bcName}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">职位：</label>
                    <div class="col-sm-8">
                        <input name="bcPosition" th:field="*{bcPosition}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">姓名：</label>
                    <div class="col-sm-8">
                        <input name="bcUserName" th:field="*{bcUserName}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">邮箱：</label>
                    <div class="col-sm-8">
                        <input name="bcMailbox" th:field="*{bcMailbox}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">微信号：</label>
                    <div class="col-sm-8">
                        <input name="bcWxNumber" th:field="*{bcWxNumber}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">微信二维码：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="bcWxImg" th:field="*{bcWxImg}">
                       <div class="file-loading">
                            <input class="form-control file-upload" id="bcWxImg" name="file" type="file" >
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">个人简介：</label>
                    <div class="col-sm-8">
                        <textarea name="bcBriefIntroduction" class="form-control">[[*{bcBriefIntroduction}]]</textarea>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">更多文件：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="bcFile" th:field="*{bcFile}">
                       <div class="file-loading">
                            <input class="form-control file-upload" id="bcFile" name="file" type="file" multiple>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">图片展示：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="bcImgList" th:field="*{bcImgList}">
                       <div class="file-loading">
                            <input class="form-control file-upload" id="bcImgList" name="file" type="file" multiple>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">用户id：</label>
                    <div class="col-sm-8">
                        <input name="userId" th:field="*{userId}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">公司id：</label>
                    <div class="col-sm-8">
                        <input name="pcId" th:field="*{pcId}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">插入时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="pcInsdate" th:value="${#dates.format(businessCard.pcInsdate, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">更新时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="pcUptime" th:value="${#dates.format(businessCard.pcUptime, 'yyyy-MM-dd')}" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">状态：</label>
                    <div class="col-sm-8">
                        <input name="pcStatus" th:field="*{pcStatus}" class="form-control" type="text">
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">录音信息：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="pcSpeech" th:field="*{pcSpeech}">
                       <div class="file-loading">
                            <input class="form-control file-upload" id="pcSpeech" name="file" type="file" multiple>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">小程序码：</label>
                    <div class="col-sm-8">
                        <input type="hidden" name="pcProgramCode" th:field="*{pcProgramCode}">
                       <div class="file-loading">
                            <input class="form-control file-upload" id="pcProgramCode" name="file" type="file" >
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "system/card";
        $("#form-card-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-card-edit').serialize());
            }
        }

        $("input[name='pcInsdate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='pcUptime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        function isValidJson(jsonString) {
            try {
                JSON.parse(jsonString);
            } catch (e) {
                return false;
            }
            return true;
        }
        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            if(isValidJson(val)){
                var previewUrls = JSON.parse(val);
            }else{
                 previewUrls = [val];
            }
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: previewUrls,
                maxFileCount: 10,
                autoReplace: true,
                multiple:true
            }).on('fileuploaded', function (event, data, previewId, index) {
                // $("input[name='" + event.currentTarget.id + "']").val(data.response.url)

                var $inputField = $("input[name='" + event.currentTarget.id + "']");
                // 获取当前输入框的值，如果不存在则初始化为空数组
                var currentUrls =isValidJson($inputField.val()) && $inputField.val() ? JSON.parse($inputField.val()) : [];

                // 将新的图片URL追加到现有URL数组中
                currentUrls.push(data.response.url);

                // 将更新后的URL数组转换为JSON字符串并存回输入框
                $inputField.val(JSON.stringify(currentUrls));
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });
    </script>
</body>
</html>